package com.google.code.sms.android.receiver;

import com.google.code.sms.android.service.DownloadServiceImpl;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;

/**
 * @author Sindre Mehus
 */
public class MediaButtonIntentReceiver extends BroadcastReceiver {

    private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
        Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);

        Intent serviceIntent = new Intent(context, DownloadServiceImpl.class);
        serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
        context.startService(serviceIntent);

        try {
            abortBroadcast();
        } catch (Exception x) {
            // Ignored.
        }
    }
}
